package cate.game.role.bag.item.msg;

import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MergeMsgOutput;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.id.MsgIdBBag;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteField;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

@ClientMsg(title = "背包物品 移除 の 通知")
public class ItemRemoveResp extends MergeMsgOutput<ItemRemoveResp> {
    @NoteField(value = "移除物品的唯一ID们")
    public List<String> uidList;

    @NoteField(value = "物品对象类型")
    public byte type;

    public ItemRemoveResp(){}

    public ItemRemoveResp(byte type) {
        this.type = type;
    }

    public ItemRemoveResp(String uid, byte type) {
        this.add(uid);
        this.type = type;
    }

    public void add(String uid) {
        if (uidList == null) {
            uidList = new ArrayList<>();
        }
        uidList.add(uid);
    }

    @JsonIgnore
    public boolean isEmpty(){
        return CollectionUtils.isEmpty(uidList);
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBBag.ITEM_REMOVE_RESP;
    }

    @Override
    public boolean merge(ItemRemoveResp another) {
        if (another == null || another.type != this.type) {
            return false;
        }
        this.uidList.addAll(another.uidList);
        return true;
    }
}
